<?php

namespace App\Http\Controllers\api;

use App\Http\Controllers\Controller;
use App\Models\product\ProductCourseModel;
use Illuminate\Http\Request;
use lxs\api\ApiResponse;

class MountController extends Controller
{

    /**
     * 获取挂载教程列表
     */
    public function getMountCourseList(Request $request): \Illuminate\Http\JsonResponse
    {
        $page = $request->input('page');
        $pageSize = $request->input('page_size');

        $model = ProductCourseModel::orderBy('sort', 'desc')->orderBy('update_time', 'desc');

        $count = $model->count();

        $list = $model->offset(($page - 1) * $pageSize)
            ->limit($pageSize)
            ->get()->toArray();

        return ApiResponse::success('获取挂载教程列表成功', ['list' => $list, 'total' => $count]);
    }


    /**
     * 获取挂载教程详情
     */
    public function getMountCourseDetail(Request $request) {
        $id = $request->input('id');

        $model = ProductCourseModel::find($id);

        if (!$model) {
            return ApiResponse::error('获取挂载教程详情失败');
        }

        return ApiResponse::success('获取挂载教程详情成功', $model->toArray());
    }

}
